/*
* BlowerSumController.java
* Created on  2015/7/27 12:19
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/7/27       longshihui    初始版本
*
*/

package com.infitecs.eyas.blower;

import com.infitecs.eyas.blower.model.BlowerSummary;
import com.infitecs.eyas.blower.service.BlowerSummaryService;
import com.infitecs.eyas.expression.service.ExpressionService;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/blower/summary")
public class BlowerSumController {

    @Autowired
    private SessionService sessionService;

    @Autowired
    private BlowerSummaryService blowerSummaryService;

    @Autowired
    private ExpressionService expressionService;

    @RequestMapping("")
    public String getPage(){
        try {
            sessionService.getCaseId();
            BlowerSummary blowerSummary = blowerSummaryService.getBlowerSummary();
            if (blowerSummary == null) {
                blowerSummaryService.insertNewSummary();
            }
        } catch (Exception e) {
            return "blower/summary";
        }
        sessionService.setEnvironment('S');
        return "blower/summary";
    }

    @RequestMapping(value = "/getCalculateInit", method = RequestMethod.POST)
    @ResponseBody
    public void getCalculateInit() {
        sessionService.putBlwerSummaryInit(sessionService.getCaseId());
    }

    @RequestMapping(value = "/getAutoCalculate", method = RequestMethod.POST)
    @ResponseBody
    public BlowerSummary getBlowerSummary() {
        BlowerSummary blowerSummary = new BlowerSummary();
        Map<String, Double> map = sessionService.getParamMap();
        blowerSummary.setE15(map.get("SE15"));
        blowerSummary.setE16(map.get("SE16"));
        blowerSummary.setE36(expressionService.calculate(new Param("SE36")));
        blowerSummary.setE37(expressionService.calculate(new Param("SE37")));
        blowerSummary.setE38(expressionService.calculate(new Param("SE38")));
        blowerSummary.setE39(expressionService.calculate(new Param("SE39")));
        blowerSummary.setE40(expressionService.calculate(new Param("SE40")));
        blowerSummary.setE41(expressionService.calculate(new Param("SE41")));
        blowerSummary.setE42(expressionService.calculate(new Param("SE42")));
        blowerSummary.setE43(expressionService.calculate(new Param("SE43")));
        blowerSummary.setE44(expressionService.calculate(new Param("SE44")));
        blowerSummary.setE45(map.get("SE45"));
        blowerSummary.setE46(expressionService.calculate(new Param("SE46")));
        blowerSummary.setE47(expressionService.calculate(new Param("SE47")));
        blowerSummary.setE48(expressionService.calculate(new Param("SE48")));
        blowerSummary.setE49(expressionService.calculate(new Param("SE49")));
        blowerSummary.setE50(expressionService.calculate(new Param("SE50")));
        blowerSummary.setE51(expressionService.calculate(new Param("SE51")));
        blowerSummary.setE52(expressionService.calculate(new Param("SE52")));
        blowerSummary.setE53(expressionService.calculate(new Param("SE53")));
        blowerSummary.setE54(expressionService.calculate(new Param("SE54")));
        blowerSummary.setE55(expressionService.calculate(new Param("SE55")));
        blowerSummary.setE56(map.get("SE56"));
        blowerSummary.setE57(expressionService.calculate(new Param("SE57")));
        blowerSummary.setE58(expressionService.calculate(new Param("SE58")));
        return blowerSummary;
    }

}
